home *** CD-ROM | disk | FTP | other *** search
- program test_clock_IBM;
-
- (******************************************************************)
- (* *)
- (* CLOCK.IBM Ver 1.0 April 7,1986 by Clarence C. Rudd *)
- (* *)
- (* Clock.LIB is a file that contains several clock routines *)
- (* for use with IBM type computer systems. *)
- (* *)
- (* To use this libaray load it into your file and then delete *)
- (* the routines not needed. *)
- (* *)
- (* NOTE: All of the user routines in this libaray are in the *)
- (* form of function calls. Example of use would be: *)
- (* *)
- (* String_variable := Date_1 + ' ' + Time_12; *)
- (* *)
- (* The String_variable would now contain the date & time *)
- (* i.e. 04/07/86 1:31:15 PM *)
- (* *)
- (******************************************************************)
-
-
- (******************************************************************)
- (* *)
- (* The following declarations and constants plus the *)
- (* Procedure Read_Clock must be in your program to use *)
- (* any of the time & date Functions. *)
-
- type
- str8 = string[8];
- str11 = string[11];
- str17 = string[17];
- str28 = string[28];
- str30 = string[30];
-
-
-
- (* These are the main procedure called by all of the time & *)
- (* date Functions . They read the info from the IBM system clock *)
- (* and converts it to bytes and store it in the following passed *)
- (* variables in the form of: *)
- (* *)
- (* Get_Date month in range 1(Jan)..12(Dec) *)
- (* day in range 1..length of month *)
- (* (calculated) and week_day in 1(Sun)..7(Sat) *)
- (* *)
- (* Get_Time hour in 0..23 (24-hr clock) *)
- (* minute and second in 0..59 *)
- (* *)
- (* NOTE: the variables are of type Byte to save space. *)
-
- {.PA}
- function Get_Day_of_Week(month, day : byte; year : integer): byte;
- var
- Leap_Year : boolean;
- DayNum, yy, cc : integer;
-
- begin
- yy := year mod 100; { get last 2 digits of year }
- cc := year div 100; { get the century }
-
- DayNum := yy; {load DayNum with year }
- DayNum := DayNum + (yy DIV 4); { add 1/4 of year, dropping remainder }
- DayNum := DayNum + day; {add day of month}
- Leap_Year := (yy MOD 4) = 0; { set true if a leap year }
- case month of { add value for month }
- 1 : if not Leap_Year then DayNum := DayNum + 1;
- 2 : if Leap_Year
- then DayNum := DayNum +3
- else DayNum := DayNum + 4;
- 3 : DayNum := DayNum + 4;
- 4 : DayNum := DayNum + 0;
- 5 : DayNum := DayNum + 2;
- 6 : DayNum := DayNum + 5;
- 7 : DayNum := DayNum + 0;
- 8 : DayNum := DayNum + 3;
- 9 : DayNum := DayNum + 6;
- 10 : DayNum := DayNum + 1;
- 11 : DayNum := DayNum + 4;
- 12 : DayNum := DayNum + 6;
- end; { of case month }
-
- case cc of { add value for century }
- 17 : DayNum := DayNum + 4;
- 18 : DayNum := DayNum + 2;
- 19 : DayNum := DayNum + 0;
- 20 : DayNum := DayNum + 6;
- end; { of case cc }
-
- (* determine day of week by dividing day by 7, remainder = day of week *)
- (* as follows: *)
- (* 1 = SUNDAY *)
- (* 2 = MONDAY *)
- (* 3 = TUESDAY *)
- (* 4 = WEDNESDAY *)
- (* 5 = THURSDAY *)
- (* 6 = FRIDAY *)
- (* 0 = SATURDAY ( GETS ADJUSTED TO A VALUE OF 7) *)
- (* *)
- DayNum := DayNum MOD 7;
- if DayNum = 0 then DayNum := 7;
- Get_Day_of_Week := DayNum;
- end; { of function Get_Day_of_Week }
-
- {.PA}
- procedure Get_Date(var month, day : byte; var year : integer);
- type
- Regpack = record
- case integer of
- 1 : (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : integer);
- 2 : (AL, AH, BL, BH, CL, CH, DL, DH : byte);
- end;
- var
- recpack: regpack; {record for MsDos call}
-
- begin
- recpack.ah := $2a ; { MsDos get date code }
- MsDos(recpack); { call function }
- with recpack do
- begin
- year := cx; {move from recpack to var }
- day := (dx mod 256); { " }
- month := (dx shr 8); { " }
- end;
- end;
-
-
- procedure Get_Time(var hour, min, sec : byte);
- type
- Regpack = record
- case integer of
- 1 : (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : integer);
- 2 : (AL, AH, BL, BH, CL, CH, DL, DH : byte);
- end;
-
- var
- recpack: regpack; {assign record}
-
- begin
- recpack.ah := $2c; {initialize correct registers}
- intr($21,recpack); {call interrupt}
- with recpack do
- begin
- hour := (cx shr 8); {convert and move to byte vars}
- min := (cx mod 256); { " }
- sec := (dx shr 8); { " }
- end;
- end;
-
-
- (* *)
- (* End of required procedure *)
- (******************************************************************)
- {.PA}
- (******************************************************************)
- (* Date_1 returns 8-character srting i.e. (04/07/86) *)
- (* *)
-
- function Date_1: str8;
-
- var
- tempm, tempd, tempy : string[2];
- month, day : byte;
- year : integer;
-
- begin
- Get_Date(month, day, year);
- str(month:1,tempm);
- if length(tempm) = 1 then tempm := '0' + tempm; {add leading 0 ?}
- str(day:1,tempd);
- if length(tempd) = 1 then tempd := '0' + tempd; {add leading 0 ?}
- str((year mod 100):1,tempy);
- Date_1 := tempm + '/' + tempd + '/' + tempy;
- end;
-
- (* *)
- (* End of Function Date_1 *)
- (******************************************************************)
- {.PA}
- (******************************************************************)
- (* Date_2 returns 17-characater string i.e. (Mon Apr 7, 1986) *)
- (* *)
-
- function Date_2: str17;
-
- const
- week_days: array [1..7] of string[3] =
- ('Sun','Mon','Tue','Wen','Thu','Fri','Sat');
- months: array [1..12] of string[3] =
- ('Jan','Feb','Mar','Apr','May','Jun',
- 'Jul','Aug','Sep','Oct','Nov','Dec');
-
- var
- tempd : string[2];
- tempy : string[4];
- month, day, week_day : byte;
- year : integer;
-
- begin
- Get_Date(month, day, year);
- week_day := Get_Day_of_Week(month,day,year);
- str(day:1,tempd);
- str(year:1,tempy);
-
- {delete the this line if you want leading zero on day of month
- if length(tempd) = 1 then tempd := '0' + tempd; {add leading 0 ?}
-
- Date_2 := week_days[week_day] + ' ' + months[month] + ' '
- + tempd + ', ' + tempy;
- end;
-
- (* *)
- (* End of Function Date_2 *)
- (******************************************************************)
- {.PA}
- (******************************************************************)
- (* Date_3 returns a string with a max length of 28 characters *)
- (* i.e. (Monday April 7, 1986) *)
- (* (Saturday December 27, 1986) *)
- (* *)
-
- function Date_3: str28;
-
- const
- week_days: array [1..7] of string[9] =
- ('Sunday','Monday','Tuesday','Wendesday','Thursday',
- 'Friday','Saturday');
- months: array [1..12] of string[9] =
- ('Janurary','February','March','April','May','June',
- 'July','August','September','October','November','December');
-
- var
- tempd : string[2];
- tempy : string[4];
- month, day, week_day, hour, min, sec : byte;
- year : integer;
-
- begin
- Get_Date(month, day, year);
- str(day:1,tempd);
- str(year:1,tempy);
- week_day := Get_Day_of_Week(month,day,year);
-
- {delete the this line if you want leading zero on day of month
- if length(tempd) = 1 then tempd := '0' + tempd; {add leading 0 ?}
-
- Date_3 := week_days[week_day] + ' ' + months[month] + ' ' +
- tempd + ', '+ tempy;
- end;
-
- (* *)
- (* End of Function Date_3 *)
- (******************************************************************)
- {.PA}
- (******************************************************************)
- (* START OF THE TIME FUNCTIONS *)
- (******************************************************************)
- (* Time_12 returns 11-character string i.e. (12:01:00 AM) *)
- (* *)
-
- function Time_12: str11;
-
- var
- pm : boolean;
- temp : string[11];
- temps, tempm, temph: string[2];
- hour, min, sec : byte;
-
- begin
- Get_Time(hour, min, sec);
- str(sec:1,temps);
- str(min:1,tempm);
- if length(temps) = 1 then temps := '0' + temps;
- if length(tempm) = 1 then tempm := '0' + tempm;
-
- if hour >= 12 then begin {if after 12 PM convert from military time}
- pm := true;
- if hour > 12 then hour := hour - 12;
- end
- else begin
- pm := false;
- if hour = 0 then hour := 12; {if 12 AM}
- end;
-
- str(hour:2,temph);
- temp := temph + ':' + tempm + ':' + temps;
-
- if pm then temp := temp + ' PM'
- else temp := temp + ' AM';
- Time_12 := temp;
- end;
-
- (* *)
- (* End of Function Time_12 *)
- (******************************************************************)
- {.PA}
- (******************************************************************)
- (* Time_24 returns 8-character string i.e. (23:01:00) *)
- (* *)
-
- function Time_24: str8;
-
- var
- temp : string[11];
- temps, tempm, temph: string[2];
- hour, min, sec : byte;
-
- begin
- Get_Time(hour, min, sec);
- str(sec:1,temps);
- str(min:1,tempm);
- str(hour:1,temph);
- if length(temps) = 1 then temps := '0' + temps;
- if length(tempm) = 1 then tempm := '0' + tempm;
- if length(temph) = 1 then temph := '0' + temph;
-
- Time_24 := temph + ':' + tempm + ':' + temps;
- end;
-
- (* *)
- (* End of Function Time_24 *)
- (******************************************************************)
- {.PA}
-
-
- begin {of main program test_clock_lib }
- writeln('This is the output of Date_1 ',Date_1);
- writeln('This is the output of Date_2 ',Date_2);
- writeln('This is the output of Date_3 ',Date_3);
- writeln('This is the output of Time_12 ',Time_12);
- writeln('This is the output of Time_24 ',Time_24);
- end. {of program test_clock_lib }
-